/*
 * ExplosionView.cpp
 *
 *  Created on: 21/06/2014
 *      Author: javier
 */

#include "ExplosionView.h"

ExplosionView::ExplosionView(SDLWindow* window, SDL_Texture* texture,
		Positionable* object) :
		cycler(12) {
	this->window = window;
	this->texture = texture;
	geometry.first = object->getX();
	geometry.second = object->getY();

	int iW = 64, iH = 64;

	for (int i = 0; i < 12; ++i) {
		clips[i].x = i * iW;
		clips[i].y = 0;
		clips[i].w = iW;
		clips[i].h = iH;
	}
	useClip = 0;
	ended = false;
	rendered = 0;
}

void ExplosionView::render(Camera& cam) {
	if (!ended) {
		SDL_Rect render = cam.getOffsetFromModel(geometry);
		window->renderTexture(texture, &render, &clips[useClip]);
		rendered++;
	}
}

void ExplosionView::update() {
	if (!ended)
		useClip = cycler.next();
	if (rendered >= 12) {
		ended = true;
	}
}

ExplosionView::~ExplosionView() {

}

